home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 185 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.4 KB

  1. Path: solon.com!not-for-mail
  2. From: krotoff@such.srcc.msu.su (Alexander Krotoff)
  3. Newsgroups: comp.lang.c.moderated,comp.std.c
  4. Subject: Function returning structure
  5. Date: 25 Jan 1996 06:45:17 -0600
  6. Organization: Research Computer Center, Moscow State University
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4e7u0t$ua@solutions.solon.com>
  10. References: <4e2ki8$l0k@solutions.solon.com> <4e5p2h$6hk@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12. X-Comment-To: Dan Pop
  13.  
  14. Dan Pop <danpop@mail.cern.ch> wrote:
  15. : bnelson@netcom.com (Bob Nelson) writes:
  16.  
  17. : >#include <stdio.h>
  18. : >
  19. : >struct T {
  20. : >    char c[81];
  21. : >};
  22. : >
  23. : >struct T func(void)
  24. : >{
  25. : >    static struct T s = { "returned from func" };
  26. : >
  27. : >    return s;
  28. : >}
  29. : >
  30. : >int main(void)
  31. : >{
  32. : >
  33. : >    printf("%s\n", func().c);    
  34. : >    return 0;
  35. : >}
  36. : The compiler has to take the address of func().c and pass it to printf.  
  37. : But func().c is not an lvalue, hence its address cannot be taken.  
  38. : I'm not sure this is the only possible interpretation, so I'm crossposting
  39. : this article to comp.std.c.
  40.  
  41. As seems to me, there is nothing to complain bout taking an address
  42. of lvalue. There is implicit conversion from array of T to pointer to T.
  43. So, I think your example is correct.
  44.  
  45. --
  46. Alexander N. Krotoff        krotoff@such.srcc.msu.su
  47. Research Computer Center    tel: +7(095)939-2638
  48. Moscow State University        fax: +7(095)939-4430
  49.